package com.cqust.junit;

import com.cqust.dao.CardDao;
import com.cqust.dao.RecordDao;
import com.cqust.entity.Card;
import com.cqust.service.CardService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import java.util.List;


public class MyUnitTest3 {

    @Test
    public void studentEnroll()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        CardService cardServic= (CardService) ac.getBean("cardService");
        int flage=cardServic.studentEnroll("2020444229","彭竹庚",22,"软件工程");
        if(flage==1)
            System.out.println("该学生已注册!");
        else
            System.out.println("注册失败");
    }

    @Test
    public void openAccount()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        CardService cardService= (CardService) ac.getBean("cardService");
        int flage=cardService.openAccount("2020444229","彭竹庚","S101",1000);
        if(flage>=0)
        {
            System.out.println("开户成功！");
        }
        else
            System.out.println("该学生不存在！开户失败！");
    }

    @Test
    public void consume()
    {
        String sno="2020444229";
        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        CardService cardService= (CardService) ac.getBean("cardService");
        CardDao cardDao= (CardDao) ac.getBean("cardDao");
        int flage=cardService.consume(sno,50);
        if(flage==1)
        {
            List<Card> cards=cardDao.selectByCondition("sno="+sno);
            System.out.println("消费成功，你的余额为："+cards.get(0).getBalance());
        }
        else
            System.out.println("该卡还未开户！！");
    }

    @Test
    public void queryConsumeRecord()
    {
        ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
        CardService cardService= (CardService) ac.getBean("cardService");
        cardService.queryConsumeRecord("2");
    }
}
